import * as dto from './DTO';
import {request, handleFetchResultNotification, REQUEST_TYPE} from '../utils';
import stringify from 'Shared/utils/stringify';
import {formatMessage} from './intl';
const baseUrl = '/parts/api/v1';

const getInitdesc = formatMessage({
    id: 'api.message.getInitdesc',
    defaultMessage: '初始化备件索赔判定书'
});
const getListDesc = formatMessage({
    id: 'api.message.getListDesc',
    defaultMessage: '查询备件索赔判定书'
});
const getDetailDesc = formatMessage({
    id: 'api.message.getDetailDesc',
    defaultMessage: '查询备件索赔判定书详情'
});
const exportDesc = formatMessage({
    id: 'api.exportDesc',
    defaultMessage: '导出备件索赔判定书'
});
const approveDesc = formatMessage({
    id: 'api.message.newVehicleSaleOrderDesc',
    defaultMessage: '审核备件索赔判定书'
});
const confirmDesc = formatMessage({
    id: 'api.message.updateDesc',
    defaultMessage: '确认备件索赔判定书'
});
//初始化
export const getInitData = () => request(`${baseUrl}/ui/partClaimDecision/init`, null, dto.InitData)
    .then(handleFetchResultNotification(REQUEST_TYPE.initQuery, getInitdesc));

// 查询订单列表
export const getList = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partClaimDecisions/forCurrentUser?${queryString}`, null, dto.List)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getListDesc));
};
// 查询详情
export const getDetail = id =>
    request(`${baseUrl}/partClaimDecisions/${id}`, null, dto.Detail)
        .then(handleFetchResultNotification(REQUEST_TYPE.query, getDetailDesc));
// 导出
export const exports = pageOption => {
    const queryString = stringify(pageOption);
    return request(`${baseUrl}/partClaimDecisions/export/forCurrentUser?${queryString}`)
        .then(handleFetchResultNotification(REQUEST_TYPE.submit, exportDesc))
        .then(res => res.data);
};
//审核
export const approveApplyReport = (id, data) => request(`${baseUrl}/partClaimDecisions/${id}/approve`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, approveDesc));

//确认
export const confirmApplyReport = (id, data) => request(`${baseUrl}/partClaimDecisions/${id}/confirm`, {
    method: 'PUT',
    headers: {'Content-Type': 'application/json'},
    body: JSON.stringify(data)
}).then(handleFetchResultNotification(REQUEST_TYPE.submit, confirmDesc));
